package com.ddm.ddm.controller;


import com.ddm.ddm.common.RestResponse;
import com.ddm.ddm.entity.Admin;
import com.ddm.ddm.service.IAdminService;
import com.ddm.ddm.vo.AdminVo;
import javax.validation.constraints.NotBlank;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lq
 * @since 2021-07-09
 */
@RestController
@RequestMapping("/admin")
public class AdminController {

  @Autowired
  private IAdminService iAdminService;

  @PostMapping(value = "save", name = "注册")
  public RestResponse saveAdmin(@RequestBody Admin admin) {
    int i = iAdminService.saveAmin(admin);
    if (i > 0) {
      return RestResponse.ok("注册成功");
    }
    return RestResponse.error("注册失败");
  }


  @PostMapping(value = "login", name = "登录")
  public RestResponse getLogin(@RequestBody AdminVo adminVo) {
    Admin admin = iAdminService.getAdmin(adminVo.getGName(), adminVo.getGPassword());
    if (admin != null) {
      return RestResponse.ok("登录成功");
    }
    return RestResponse.error("登录失败");
  }
}
